<?php namespace Cy\Controller;

class IndexController extends \Hdphp\Controller\Controller{
	public function index(){
		$_GET['wxid'] =isset($_GET['wxid'])?$_GET['wxid']:$_SESSION['wxid'];
		$_SESSION['wxid'] = $_GET['wxid'];
		$data = Db::table('shop')->where('wxid',$_GET['wxid'])->get();
		View::with('data',$data)->make();
	}
	//显示菜品列表
	public function lists(){
		$dpid = Q('dpid');
		$data  = Db::table('shop_goods')->where('dpid',$dpid)->get();
		$dp = Db::table('shop')->where('id',$dpid)->first();
		$_SESSION['dpid'] = $dpid;
		View::with('dp',$dp);
		View::with('data',$data)->make();
	}

	//把前端储存的购物车数据存在服务器的session中
	public function saveCart(){

		$_SESSION['cart']=$_POST;
		
		
	}
	//结算
	public function order(){
		if(IS_POST)
		{
			$_POST['dpid'] = $_SESSION['dpid'];
			$_POST['book_time'] = time();
			$_POST['goods']=serialize($_SESSION['cart']);
			if(Db::table('shop_order')->insert($_POST)){
				View::ajax(array('code'=>0,'message'=>'订餐成功'));
			}
			else{
				View::ajax(array('code'=>0,'message'=>'订餐失败'));
			}
		}
		else{
			$d = Db::table('shop_goods')->whereIn('id',array_keys($_SESSION['cart']['data']))->get();
			View::make();
		}
	}
}













